﻿using Microsoft.Extensions.Logging;
using WorkflowFramework;

namespace WorkFlowDemo.Steps
{
    public class Step1 : FlowStepBase
    {
        public override string StepName => "Step1";

        private readonly ILogger<Step1> _logger;
        public Step1(ILogger<Step1> logger)
        {
            _logger=logger;
        }
        public override async Task InitializeAsync()
        {
            await Task.Delay(500);
            _logger.LogInformation($"InitializeAsync");
        }
        public override async Task PreProcessAsync()
        {
            await Task.Delay(100);
            _logger.LogInformation($"PreProcessAsync");
        }
        public override async Task PostProcessAsync()
        {
            await Task.Delay(200);
            _logger.LogInformation($"PostProcessAsync");
        }
        public override async Task<FlowStepResult> ExecuteAsync()
        {
            _logger.LogInformation($"Executing Step 1...");
            //Console.WriteLine("");
            await Task.Delay(500);
            // 模拟随机失败
            if (Random.Shared.Next(0, 10) > 7)
            {
                throw new Exception("Step 1 failed randomly");
            }
            return FlowStepResult.Success();
        }
    }
}
